package com.wwc.sc.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.wwc.sc.pojo.Dept;
import com.wwc.sc.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.UUID;

/**
 * @author WWC
 */
@RestController
public class DeptController {

    @Autowired
    private DeptService deptService;


    @GetMapping("/dept/queryDept/{deptNo}")
    @HystrixCommand(fallbackMethod = "hystrixQueryDept")
    public Dept queryDept(@PathVariable("deptNo") String deptNo){
        Dept dept = deptService.queryDept(deptNo);
        if (dept == null) {
            throw new RuntimeException("deptNo = "+deptNo+" 无法查到该信息，或者该用户不存在！");
        }

        return dept;
    }

    public Dept hystrixQueryDept(@PathVariable("deptNo") String deptNo){
        Dept dept = new Dept();
        dept.setDeptNo(deptNo);
        dept.setDeptName("deptNo = "+deptNo+" 无法查到该信息，或者该用户不存在！");
        dept.setScSource("no this database in MYSQL");
        if (dept == null) {
            throw new RuntimeException("id = "+deptNo+" 无法查到该信息，或者该用户不存在！");
        }

        return dept;
    }

}
